package com.json.infoboard.contorll;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.common.JsonResult;
import com.json.infoboard.service.IInfoboardServiceJson;
import com.json.infoboard.vo.InfoboardJson;

@Controller
@RequestMapping("/infoboard")
public class InfoboardControllerJson {

	@Autowired
	private IInfoboardServiceJson infoboardServiceJson;
	
	@ResponseBody
	@RequestMapping("/view_instant_Infoboard_json")
	public JsonResult view_instant_Infoboard_json(ModelMap model,Integer sec){
		List<InfoboardJson> infoboardes = infoboardServiceJson.selectInfoboard(sec);
		Integer total = infoboardServiceJson.selectInfoboardCount(sec);
		JsonResult result = new JsonResult();
		result.setTotal(total);
		result.setResults(infoboardes);
		return result;
	}
	
	/**
	 * @Title: initBinder
	 * @Description: 注册日期处理
	 * @param binder
	 * @throws
	 */
	@InitBinder
	public void initBinder(WebDataBinder binder) {
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		dateFormat.setLenient(false);
		binder.registerCustomEditor(Date.class, new CustomDateEditor(
				dateFormat, false));
	}
}
